package com.hongxin.nw.netty.utils.pools;

import com.hongxin.nw.netty.values.TypeIdentif;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 设备编码对应直流/交流 列表操作
 */
public class CodeTypePools {
    //业务系统:1标识直流,2标识交流,南网协议:1标识交流,2标识直流,,两者,此处对应业务系统
    //直流
    private final static int TYPE_DIRECT = 1;
    //交流
    private final static int TYPE_COMM = 2;
    //设备编号 对应 设备直流/交流
    private final static Map<String, Integer> typeList = new ConcurrentHashMap<>();
    public static int getSize(){
        return typeList.size();
    }
    public static int getCodeType(final String code) throws Exception {
        if (typeList.containsKey(code)){
            return typeList.get(code);
        }else{
            throw new Exception("设备类型(交流/直流)数据找不到,设备: " + code);
        }
    }
    public static void addCodeType(final String code, final int type) {
        //转成本系统的对应值
        int myType = TYPE_DIRECT == type ? TypeIdentif.EQUIPMENT_DIRECT.getInt() : TypeIdentif.EQUIPMENT_COMMUNICATION.getInt();
        typeList.put(code, myType);
    }
    public static void removeCodeType(final String code) {
        if (typeList.containsKey(code)){
            typeList.remove(code);
        }
    }
}